package com.xinnet.mms.allot.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.xinnet.core.dao.impl.BaseDaoImpl;
import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.allot.dao.CustomMixDao;
import com.xinnet.mms.entity.CustomMix;
import com.xinnet.mms.entity.CustomMixAudit;
import com.xinnet.mms.entity.CustomMixDept;

@Repository("customDaoImpl")
public class CustomMixDaoImpl extends BaseDaoImpl<CustomMix, Long> implements CustomMixDao {

	//分页查询所有已分配的客户
	@Override
	public PageView<CustomMix> queryAllCustomer(PageView<CustomMix> pageView) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		pageView.setRecords(this.getSqlSession().selectList("custommix.queryAllCustomer",map));
		return pageView;
	}

	//查询调配弹窗的信息
	@Override
	public CustomMixDept showInMixDiv(String cusId) throws SQLException {
		return this.getSqlSession().selectOne("custommix.showInMixDiv",cusId);
	}

	//添加客户调配信息进入客户调配审核
	@Override
	public void addCustomMixAudit(CustomMixAudit customMixAudit) throws SQLException {
		this.getSqlSession().insert("custommix.addCustomMixAudit",customMixAudit);
	}

	//通过查询条件过滤客户调配页面客户信息
	@Override
	public PageView<CustomMix> queryCustomMixByTrem(PageView<CustomMix> pageView,CustomMix customMix) throws SQLException {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("paging", pageView);
		map.put("t", customMix);
		pageView.setRecords(this.getSqlSession().selectList(this.getClassName()+".queryCustomerByTrem", map));
		return pageView;
	}
	
	public void updateCustomMixAuditByEcrId(String ecrId){
		this.getSqlSession().update("custommix.updateCustomMixAuditByEcrId",ecrId);
	}

	/**
	 * 修正审核中但未显示的错误记录
	 */
	@Override
	public void updateCustomflagByEmpno(String empno) throws SQLException {
		this.getSqlSession().update("custommix.updateCustomflagByEmpno",empno);
	}

	/**
	 * 
	 */
	@Override
	public CustomMixAudit getCustomMixAuditById(String id) throws SQLException {
		return this.getSqlSession().selectOne("custommix.getCustomMixAuditById",id);
	}

	@Override
	public PageView<CustomMixAudit> queryMixCustomersByCondition(
			PageView<CustomMixAudit> pageView,CustomMixAudit customMixAudit) {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("mm", customMixAudit);
		map.put("page", pageView);
		pageView.setRecords(this.getSqlSession().selectList("custommix.showMisCustomer", map));
		return pageView;
	}

	@Override
	public Integer queryMixCustomerCount(CustomMixAudit customMixAudit) {
		// TODO Auto-generated method stub
		return this.getSqlSession().selectOne("custommix.showMisCustomerCount",customMixAudit);
	}

	@Override
	public void updateCustomMixAudit(CustomMixAudit customMixAudit) {
		// TODO Auto-generated method stub
		this.getSqlSession().update("custommix.updateCustomMixAuditByEntity",customMixAudit);
	}
	
}
